gtk: Allow selection models to take null list model during construction
authorJason Francis <jason@cycles.network>
Mon, 15 Mar 2021 13:30:33 +0000 (09:30 -0400)
committerJason Francis <jason@cycles.network>
Mon, 15 Mar 2021 19:55:47 +0000 (15:55 -0400)
This brings it in line with the documentation, and with the respective
set_model() functions.

gtk/gtkmultiselection.c
gtk/gtknoselection.c
gtk/gtksingleselection.c
testsuite/gtk/multiselection.c
testsuite/gtk/singleselection.c

index 2b60ab83020469ef4e19277240094decb58b52e8..3df394d1d1a2bacf20702bd8903699907d234b84 100644 (file)
@@ -378,7 +378,7 @@ gtk_multi_selection_new (GListModel *model)
 {
   GtkMultiSelection *self;
 
-  g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
+  g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
 
   self = g_object_new (GTK_TYPE_MULTI_SELECTION,
                        "model", model,
index 36d4de008dd032cb2977788312ebd253300d979d..bc7363bbb8b86b2cc61560a0e91df0e12497999b 100644 (file)
@@ -224,7 +224,7 @@ gtk_no_selection_new (GListModel *model)
 {
   GtkNoSelection *self;
 
-  g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
+  g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
 
   self = g_object_new (GTK_TYPE_NO_SELECTION,
                        "model", model,
index ad1cba64869deb819593a4c649181c461408ceb6..fcdd91150354314107425d2e37d8a7756862dff9 100644 (file)
@@ -460,7 +460,7 @@ gtk_single_selection_new (GListModel *model)
 {
   GtkSingleSelection *self;
 
-  g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
+  g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
 
   self = g_object_new (GTK_TYPE_SINGLE_SELECTION,
                        "model", model,
index bbfaa2330f026ff31faa0b1344e7947eeb4ce5a3..c1457488e36ded72aa0f1f483be7c383bcf06cd8 100644 (file)
@@ -304,6 +304,17 @@ test_create (void)
   g_object_unref (selection);
 }
 
+static void
+test_create_empty (void)
+{
+  GtkMultiSelection *selection;
+
+  selection = gtk_multi_selection_new (NULL);
+  g_assert_cmpint (g_list_model_get_n_items (G_LIST_MODEL (selection)), ==, 0);
+
+  g_object_unref (selection);
+}
+
 static void
 test_changes (void)
 {
@@ -682,6 +693,7 @@ main (int argc, char *argv[])
   selection_quark = g_quark_from_static_string ("Mana mana, badibidibi");
 
   g_test_add_func ("/multiselection/create", test_create);
+  g_test_add_func ("/multiselection/create-empty", test_create_empty);
 #if GLIB_CHECK_VERSION (2, 58, 0) /* g_list_store_splice() is broken before 2.58 */
   g_test_add_func ("/multiselection/changes", test_changes);
 #endif
index b94b38091fe220187cdbde4dfd863539784acf8f..85e1f4163baba0f6ca8b9bc33f96444a3a7a1723 100644 (file)
@@ -304,6 +304,17 @@ test_create (void)
   g_object_unref (selection);
 }
 
+static void
+test_create_empty (void)
+{
+  GtkSingleSelection *selection;
+
+  selection = gtk_single_selection_new (NULL);
+  g_assert_cmpint (g_list_model_get_n_items (G_LIST_MODEL (selection)), ==, 0);
+
+  g_object_unref (selection);
+}
+
 static void
 test_changes (void)
 {
@@ -706,6 +717,7 @@ main (int argc, char *argv[])
   selection_quark = g_quark_from_static_string ("Mana mana, badibidibi");
 
   g_test_add_func ("/singleselection/create", test_create);
+  g_test_add_func ("/singleselection/create-empty", test_create_empty);
   g_test_add_func ("/singleselection/autoselect", test_autoselect);
   g_test_add_func ("/singleselection/autoselect-toggle", test_autoselect_toggle);
   g_test_add_func ("/singleselection/selection", test_selection);